<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>修改密码--layui后台管理模板 2.0</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="../plugins/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="../css/public.css" media="all" />
</head>
<body class="childrenBody">
<form class="layui-form layui-row changePwd">
	<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
		<!--<div class="layui-input-block layui-red pwdTips">旧密码请输入“123456”，新密码必须两次输入一致才能提交</div>-->
		<div class="layui-form-item">
			<label class="layui-form-label">用户名</label>
			<div class="layui-input-block">
				<input type="text" value="" name="userName"  disabled class="layui-input layui-disabled">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">旧密码</label>
			<div class="layui-input-block">
				<input type="password" name="oldPassword" placeholder="请输入旧密码" lay-verify="required|oldPwd" class="layui-input pwd">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">新密码</label>
			<div class="layui-input-block">
				<input type="password"name="newPassword" placeholder="请输入新密码" lay-verify="required|newPwd" id="oldPwd" class="layui-input pwd">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">确认密码</label>
			<div class="layui-input-block">
				<input type="password" value="" placeholder="请确认密码" lay-verify="required|confirmPwd" class="layui-input pwd">
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit="" lay-filter="changeInfo">立即修改</button>
			</div>
		</div>
	</div>
</form>
<script type="text/javascript" src="../plugins/layui/layui.js"></script>
<script>
    layui.use(['form','layer','laydate','table','laytpl'],function() {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            laytpl = layui.laytpl,
            table = layui.table;
        //添加验证规则
        form.verify({
//            oldPwd : function(value, item){
//                if(value != "123456"){
//                    return "密码错误，请重新输入！";
//                }
//            },
//            newPwd : function(value, item){
//                if(value.length < 6){
//                    return "密码长度不能小于6位";
//                }
//            },
            confirmPwd : function(value, item){
                if(!new RegExp($("#oldPwd").val()).test(value)){
                    return "两次输入密码不一致，请重新输入！";
                }
            }


        })
        //提交更新
        form.on('submit(changeInfo)', function(data){


            $.ajax({
                url:"/managerController/changePwd",
                type:"POST",
                data:data.field,
                dataType:"json",
                success:function(data){
                    if(data.code == -1){
                        top.location.href="/page/login"
                    }
                    else if (data.ret ==14 ||data.ret == "14"){
                        layer.alert('更新成功', {icon: 1}, function(index){
                            layer.closeAll("page");
                            layer.close(index);
                            location.href=location.href;
                        });
                    }
                    else if (data.ret =="15"||data.ret == 15){
                        layer.alert('更新失败', {icon: 5});
                    }
                    else if (data.ret =="020002"||data.ret == 020002){
                        layer.alert('旧密码错误', {icon: 5});
                    }

                }
            })
            return false;
        });
        $(function () {
            $.ajax({
                url:"/managerController/getAdmin",
                type:"POST",
                dataType:"json",
                success:function (data) {
                    $('input[name="userName"]').val(data.manager.userName)

                }
            })
        })

    })

</script>
</body>
</html>